/*
 * @Author: liuzhongpei 
 * @Date: 2020-09-14 18:53:32 
 * @Last Modified by: liuzhongpei
 * @Last Modified time: 2020-09-14 19:03:52
 */
//引入模块
const Koa = require('koa')
const app = new Koa()
const loger = require('./log_middlewere')
//定义接口
app.use(async (ctx, next) => {
    if (ctx.path === '/') {
        ctx.body = "Hi koa!"
    }
    //向下执行
    await next()
})
//使用loger中间件
app.use(loger)
//中间件运行流程
// app.use(async (ctx, next) => {
//     if (ctx.path === '/') {
//         ctx.body = '1'
//         await next()
//         console.log('5')
//     }
// });
// app.use(async (ctx, next) => {
//     if (ctx.path === '/') {
//         ctx.body+=',2'
//         await next()
//         console.log('4')
//     }

// });
// app.use(async (ctx, next) => {
//     if (ctx.path === '/') {
//         ctx.body +=',3'
//     }
// });

//监听端口
app.listen(3000, () => {
    console.log('koa is running at to 3000 http://localhost:3000/')
});